<?php if(!defined('HDPHP_PATH'))exit;C('SHOW_NOTICE',FALSE);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <title>商品管理</title>
    <script type="text/javascript" src="http://localhost/jumei/Static/js/jquery-1.7.2.min.js"></script>
    <link rel="stylesheet" href="http://localhost/jumei/Static/bootstrap/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="http://localhost/jumei/Static/hdjs/hdjs.css">
    <script type="text/javascript" charset="utf-8" src="http://localhost/jumei/Static/ueditor1_4_3/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="http://localhost/jumei/Static/ueditor1_4_3/ueditor.all.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="http://localhost/jumei/Static/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
</head>
<body>
<div class="wrap">
    <div class="hd-title-header">修改商品</div>
    <form action="" method="post" class="form-inline hd-form" enctype="multipart/form-data">
        <table class="hd-table hd-table-list">
            <tr>
                <th class="w100" width="100">商品名称</th>
                <td  class="w100" width="750">
                    <input type="text" name="gname" class="w200" value="<?php echo $data[0]['gname'];?>" /> 
                </td>
                <td></td>
            </tr>
            <tr>
                <th class="w100">所属分类</th>
                <td>
                    <select name="f_category_cid" class="w200" id="good-cate">
                        <option value="0">请选择类型</option>
                        <?php foreach ($cateData as $k=>$v){?>
                            <option value="<?php echo $v['cid'];?>"     <?php if($data[0]['f_category_cid']==$v['cid']){ ?>selected="selected"<?php } ?>><?php echo $v['_name'];?></option>
                        <?php }?>
                    </select>
                </td>
                <td></td>
            </tr>
            <script type="text/javascript">
            $(function(){
                $('#good-cate').change(function() {
                    $('.good-attr').fadeIn(200);
                    $('.good-class').fadeIn(200);
                    var num = $(this).val();
                    $.ajax({
                        url: "<?php echo U('Goods/ajax_type');?>",
                        type: 'post',
                        dataType: 'json',
                        data: {cid: num},
                        success:function(data){
                            if (data != 0){
                                var attr, spec, tmp;
                                    attr = spec = '';
                                for (var i in data)
                                {
                                    tmp = '';
                                    tmp += '<tr class="info">';
                                    tmp += '<td align="right">' + data[i].taname + '</td>';
                                    tmp += '<td>';
                                    // str = "<?php foreach ( as =>){?><?php }?>";
                                    if (data[i].tavalue == '')
                                    {
                                        tmp += '<input type="text" name="';

                                        if (data[i].class == 0)
                                        {
                                            tmp += 'attr[' + data[i].taid +']';
                                        }
                                        else
                                        {
                                            tmp += 'spec[' + data[i].taid + '][tavalue][]';
                                        }
                                        
                                        tmp += '"/>';
                                    }
                                    else
                                    {
                                        tmp += '<select name="';

                                        if (data[i].class == 0)
                                        {
                                            tmp += 'attr[' + data[i].taid +']';
                                        }
                                        else
                                        {
                                            tmp += 'spec[' + data[i].taid + '][tavalue][]';
                                        }

                                        tmp += '">';
                                        tmp += '<option value="0">-请选择-</option>';
                                        var opt = data[i].tavalue.split(',');
                                        var len = opt.length;
                                        for (var j = 0; j < len; ++j)
                                        {
                                            tmp += '<option value="' + opt[j] + '">' + opt[j] + '</option>';
                                        }
                                        tmp += '</select></td>';
                                    }
                                    if (data[i].class == 1)
                                    {
                                        tmp += '<td>附加价格 <input type="text" name="spec[' + data[i].taid +'][added][]"/>';
                                        tmp += '<span class="add-spec btn btn-success btn-sm"><i class="icon-plus icon-white"></i>添加规格</span>';
                                    }else{
                                        tmp +='<td></td>';
                                    }
                                    tmp += '</td>';
                                    tmp += '</tr>';

                                    if (data[i].class == 0)
                                    {
                                        attr += tmp;
                                    }
                                    else
                                    {
                                        spec += tmp;
                                    }
                                }
                                // $('#attr').empty().append(attr);
                                // $('#spec').empty().append(spec);
                                // alert(spec);
                                $('.info').empty();
                                $('#goods-attr').after(attr);
                                $('#goods-class').after(spec);
                            }else{
                                $('.info').empty();
                            }
                        }
                    })
                    
                    
                });
                $('#good-cate').trigger('change');
            })
            </script>
            <tr>
                <th class="w100">商品货号</th>
                <td  class="w100">
                    <input type="text" name="num" class="w200" value="<?php echo $data[0]['num'];?>"/>
                </td>
                <td></td>
            </tr>
            <tr>
                <th class="w100">计数单位</th>
                <td>
                    <input type="text" name="unit" class="w200" value="<?php echo $data[0]['unit'];?>"/>
                </td>
                <td></td>
            </tr>
            <tr>
                <th class="w100">所属品牌</th>
                <td>
                    <select name="f_brand_bid" class="w200">
                        <option value="0">请选择品牌</option>
                        <?php foreach ($brandData as $k=>$v){?>
                            <option value="<?php echo $v['bid'];?>"     <?php if($data[0]['f_brand_bid']==$v['bid']){ ?>selected="selected"<?php } ?>><?php echo $v['bname'];?></option>
                        <?php }?>
                    </select>
                </td>
                <td></td>
            </tr>
            <tr>
                <th class="w100">市场价格</th>
                <td>
                    <input type="text" name="old_price" class="w200" value="<?php echo $data[0]['old_price'];?>"/>
                </td>
                <td></td>
            </tr>
            <tr>
                <th class="w100">商城价格</th>
                <td>
                    <input type="text" name="new_price" class="w200" value="<?php echo $data[0]['new_price'];?>"/>
                </td>
                <td></td>
            </tr>
            <tr>
                <th class="w100">点击次数</th>
                <td>
                    <input type="text" name="click" class="w200" value="<?php echo $data[0]['click'];?>"/>
                </td>
                <td></td>
            </tr>
            <tr>
                <th class="w100">商品图片</th>
                <td id="logo-td">
                        <?php if($data[0]['gpic']){ ?>
                        <img src="http://localhost/jumei/<?php echo $data[0]['gpic'];?>" alt="" width="100" />
                        <a href="javascript:;" style="color:red;font-size:18px" id="close-logo">X</a>
                    <?php }else{ ?>
                        <input type="file" name="gpic" id="" />
                    <?php } ?>
                </td>
                <td></td>
            </tr>
            <script type="text/javascript">
                $('#close-logo').click(function() {
                    var input = '<input type="file" name="gpic" id="" />';
                    $('#logo-td').html(input);
                    $('#logo-src').val('');
                });
            </script>
            <tr id="goods-attr">
                <td></td>
                <th class="w100">商品属性</th>
                <td></td>
            </tr>
            <!-- <tr class="good-attr" style="display:none">
                <td  class="w100">
                    属性名:
                </td>
                <td>
                    <select name="gavalue[]" class="w200">
                        <option value="">属性值</option>
                        <?php foreach ($type_data as $k=>$v){?>
                            <option value="<?php echo $v['tid'];?>"><?php echo $v['tname'];?></option>
                        <?php }?>
                    </select>
                </td>
                <td></td>
            </tr> -->
            <tr id="goods-class">
                <td></td>
                <th class="w100">商品规格</th>
                <td></td>
            </tr>
            <!-- <tr class="good-class" style="display:none">
                <td  class="w100">
                    规格名:
                </td>
                <td>
                    <select name="gavalue" class="w200" style="margin-right:30px">
                        <option value="">属性值</option>
                        <?php foreach ($type_data as $k=>$v){?>
                            <option value="<?php echo $v['tid'];?>"><?php echo $v['tname'];?></option>
                        <?php }?>
                    </select>
                     附加金额
                    <input type="text" name="" id="money" style="margin-right:30px" />
                    <input type="button" value="添加规格" id="add-class" class="btn btn-success" />
                </td>
                <td></td>
            </tr> -->
            <script type="text/javascript">
                // $('#add-class').click(function() {
                //     var tr = $(this).parents('tr');
                //     var clone = tr.clone();
                //     var del = '<input type="button" value="删除规格" class="btn btn-danger" />';
                //     clone.find('#add-class').remove();
                //     clone.find('#money').after(del);
                //     tr.after(clone);
                //      $('.btn-danger').click(function() {
                //         // alert(1);
                //         $(this).parents('tr').remove();
                //     });
                // });
                //添加一个规格
                $('.add-spec').live('click', function () {
                    var tr = $(this).parents('tr');
                    var obj = tr.clone();
                    var del = '<span class="del-spec btn btn-info"><i class="icon-white icon-minus"></i>删除规格</span>';
                    obj.find('td').eq(3).find('.add-spec').remove();
                    obj.find('td').eq(3).append(del);
                    tr.after(obj);
                });

                //删除一个规格
                $('.del-spec').live('click', function() {
                    $(this).parents('tr').remove();
                });
            </script>
            <tr>
                <th class="w100">商品详细信息</th>
                <td>
                    <script id="editor-first" type="text/plain" style="width:704px;height:150px;" name="gdetail"></script>
                    <script type="text/javascript">
                        var ue = UE.getEditor('editor-first');
                    </script>
                </td>
                <td></td>
            </tr>
            <tr>
                <th class="w100">商品售后服务</th>
                <td>
                    <script id="editor-second" type="text/plain" style="width:704px;height:150px;" name="after_sale"></script>
                    <script type="text/javascript">
                        var ue = UE.getEditor('editor-second');
                    </script>
                </td>
                <td></td>
            </tr>
        </table>
        <div class="position-bottom">
            <input type="hidden" name="gpic" value="<?php echo $data[0]['gpic'];?>" id="logo-src" />
            <input type="submit" class="btn btn-primary" value="修改" style="margin:20px" />
        </div>
    </form>
</div>
</body>
</html>